local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent());
local ItemTool=_G.CommonOHOH.load.ItemTool();
local BigNumberHelper = CommonOHOH.load.BigNumberHelper();
local TweenHelper = CommonOHOH.load.TweenHelper();
local hurtTw = TweenInfo.new(0.15, Enum.EasingStyle.Quad,Enum.EasingDirection.Out);

local SkibiHP={
    [1]=CommonOHOH:GetPath_Loop("SkibiHP_1",game.ReplicatedStorage.Resource.UI),
    [2]=CommonOHOH:GetPath_Loop("SkibiHP_2",game.ReplicatedStorage.Resource.UI),
    [3]=CommonOHOH:GetPath_Loop("SkibiHP_3",game.ReplicatedStorage.Resource.UI)
}

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
    self.Drop=self.parent.Drop

    local root=self.parent:GetRootPart_Loop()
    local hpAtt= self.parent:GetHurtAtt()
    if not hpAtt then
        hpAtt=Instance.new("Attachment",root)
        hpAtt.CFrame=CFrame.new(Vector3.new(0, 10,0))
    end
    local sizeId=self.parent:GetSizeId()
   
    self.HpUI= SkibiHP[sizeId]:Clone()
    self.HpUI.Parent=hpAtt
    self.HpSacle=CommonOHOH:GetPath_Loop("Frame.HP.scale",self.HpUI)
    self.HpValue=CommonOHOH:GetPath_Loop("Frame.HP.num",self.HpUI)

    self.RewardUI=CommonOHOH:GetPath_Loop("Reward",self.HpUI)
    self.RewardIcon=CommonOHOH:GetPath_Loop("ImageLabel",self.RewardUI)
    self.RewardCount=CommonOHOH:GetPath_Loop("TextLabel",self.RewardUI)

    if self.Drop then
        for k,v in pairs(self.Drop) do
            local icon =ItemTool.GetItemShowView(k)
            self.RewardIcon.Image=icon
            self.RewardCount.Text=BigNumberHelper:ToString(v)
        end
    else
        self.RewardUI.Visible=false
    end

    self:UpdHp(self.parent.attribute.Hp,self.parent.attribute.MaxHp)

    self.parent:AttributeValueChanged("Hp",function()
        self:UpdHp(self.parent.attribute.Hp,self.parent.attribute.MaxHp)
    end)

end;

function M.dtor(self)
	M.super.dtor(self);
end


function M.UpdHp(self,hp,maxHp)
    self.HpValue.Text=BigNumberHelper:ToString(math.floor(hp+0.5)).."/"..BigNumberHelper:ToString(maxHp)
    local t=nil
    t=TweenHelper:PlayTween(self.HpSacle, hurtTw, {
        Size =UDim2.fromScale(hp/maxHp,1)
    },function()
        t:Destroy()
    end);
    
end


return M